package demo4;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: 李白
 * @Created: 2024/4/25 15:09
 */
public class Test {
    public static void running(IRun iRun){
        iRun.run();
    }
    public static void swiming(ISwim iSwim){
        iSwim.swim();
    }
    public static void flying(IFly iFly){
        iFly.fly();
    }

    public static void main(String[] args) {
        running(new Dog("lisi",10));
        running(new Dog("wangwu",10));
        running(new Dog("liuneng",10));
        swiming(new Frog("lishi",20));
        swiming(new Frog(" ",20));
    }
/*
    public static void func(Animal animal){//向上转型
        animal.eat();//动态绑定
    }
*/
    public static void main1(String[] args) {
        Animal animal = new Dog("lisi",10);
        animal.eat();
      //  func(new Dog("二蛋",10));
      /*  Duck duck = new Duck("大黄",10);//构造方法在创建对象是就调用了
        duck.fly();
        duck.run();
        duck.swim();*/
    }
}
class Animal{
    public String name;
    public int age;
    public Animal(String name,int age){
        this.name = name;
        this.age = age;
    }
    void eat(){
    }
}
interface IRun{
    public abstract void run();//借口方法必须重写
}
interface ISwim{
    public abstract void swim();
}
interface IFly{
    public abstract void fly();
}
class Dog extends Animal implements IRun{
    public Dog(String name,int age){
        super(name,age);
    }

    @Override
    public void run() {
        System.out.println(this.name+"正在跑");
    }

    @Override
    void eat() {
        System.out.println(this.name+"在吃狗粮");
    }
}
class Frog extends Animal implements ISwim,IRun{
    public Frog(String name,int age){
        super(name,age);
    }
    public void swim(){
        System.out.println(this.name+"正在游泳");
    }
    public void run(){
        System.out.println(this.name+"正在跑");
    }
    @Override
    void eat() {
        System.out.println(this.name+"蛙吃");
    }
}
class Duck extends Animal implements IRun,IFly,ISwim{
    public Duck(String name,int age){
        super(name,age);
    }
    public void run(){
        System.out.println(this.name+"在跑");
    }
    public void swim(){
        System.out.println(this.name+"在游泳");
    }
    public void fly(){
        System.out.println(this.name+"在飞");
    }
    @Override
    void eat() {
        System.out.println(this.name+"鸭吃");
    }
}